﻿myApp.controller('ConversionCalculatorController', function ($scope, $http, ngTableParams, $filter, $templateCache) {
    $scope.$emit('newPageLoaded', {
        'title': 'Unit Conversion Calculator | ShiJie Property',
        'description': 'Unit Conversion Calculator. Convert Hectares To Acres & Vice Versa Using This Simple Calculator. Go Now!',
        'keywords': 'unit conversion calculator, conversion calculator'
    });

    //$scope.$emit('newPageLoaded', { 'title': 'Penang Realty 世界地產 Conversion Calculator', 'description': 'Free online Conversion calculator. Try it now.' });

    pageInit();

    function pageInit() {
        
    }



    $scope.listName = [

        'Hectare - Acres',
        'Acre - Sq Feet',
        'Acre - Meter Sq',
        'Relong - Sq Feet',
        'Meter Sq - Sq Feet',
        'Rantai - Feet',
        'Meter - Feet',
        'Milimeter - Feet',
        'Link - Feet'
    ];


   


    $scope.selectedItem = {};

    $scope.convertList = [{
        'id': 1,
        'base': 'Hectare',
        'convertUnit': 'Acres',
        'formula': 2.471,
        'name': 'Hectare - Acres',

    }, {
        'id': 2,
        'base': 'Acre',
        'convertUnit': 'Sq Feet',
        'formula': 43560,
        'name': 'Acre - Sq Feet',
    }, {
        'id': 3,
        'base': 'Acre',
        'convertUnit': 'Meter Sq',
        'formula': 4046.86,
        'name': 'Acre - Meter Sq',
    }, {
        'id': 4,
        'base': 'Relong',
        'convertUnit': 'Sq Feet',
        'formula': 30976,
        'name': 'Relong - Sq Feet',
    }, {
        'id': 5,
        'base': 'Meter Sq',
        'convertUnit': 'Sq Feet',
        'formula': 10.7639,
        'name': 'Meter Sq - Sq Feet',
    }, {
        'id': 6,
        'base': 'Rantai',
        'convertUnit': 'Feet',
        'formula': 66,
        'name': 'Rantai - Feet',
    }, {
        'id': 7,
        'base': 'Meter',
        'convertUnit': 'Feet',
        'formula': 3.281,
        'name': 'Meter - Feet',
    }, {
        'id': 8,
        'base': 'Milimeter',
        'convertUnit': 'Feet',
        'formula': 0.003281,
        'name': 'Milimeter - Feet',
    },
    {
        'id': 9,
        'base': 'Link',
        'convertUnit': 'Feet',
        'formula': 0.66,
        'name': 'Link - Feet',
    }];

    $scope.changePage = function () {

    }

    $scope.inputKeyUp = function () {

        $scope.baseOutput = $scope.baseInput * $scope.selectedItem.formula;
    }

    $scope.outputKeyUp = function () {

        $scope.baseInput = $scope.baseOutput / $scope.selectedItem.formula;
    }

    $scope.selectedItem = $scope.convertList[0];
    $scope.itemName = $scope.convertList[0].name;

    $scope.initSelect = function () {

        console.log($scope.selectedItem);
    }

    $scope.selectItem = function (status,index) {
        $scope.itemChanged = status;
        $scope.selectedItem = $scope.convertList[index]
        $scope.itemName = $scope.convertList[index].name;
    }

   // $scope.selectItem(false, 0);
   




   

});